@extends('admin.common.admin')
@section('cnt')
    <article class="page-container">
        {{--消息提示--}}
        @include('admin.common.msg')
        <form class="from form-horizontal" id="roleedit" action="{{route('admin.role.update',$role)}}" method="post">
            @csrf
            @method('PUT')
            <div class="row cl">
                <label class="form-label col-sm-2">
                    <span class="c-red">*</span>角色名称：
                </label>
                <div class="formControls col-sm-8">
                    <input type="text" class="input-text" value="{{$role->name}}" name="name">
                </div>
            </div>
            <div class="row cl" style="margin-top: 20px">
                <div class="col-sm-10 col-sm-offset-2">
                    <input type="submit" class="btn btn-primary radius" value="确认修改">
                </div>
            </div>

        </form>
    </article>
@endsection
@section('js')
    <script>
        //获取角色id
        let id ={{$role->id}}
        //表单验证
        $('#roleedit').validate({
            //验证规则
            rules: {
                name: {
                    required: true,
                    minlength: 2
                }
            },
            //取消回车事件
            onkeyup: false,
            //验证成功时的样式名称
            success: 'valid',
            //验证成功后，回调事件
            submitHandler: function (form) {
                //ajax提交
                //请求url
                let url=$(form).attr('action');
                //获取表单中的数据，序列化
                $formData=$(form).serialize();
                $.post(url,$formData,res=>{
                    parent.window.document.querySelector('#name_'+id).innerHTML=res.data.name;
                    //关闭模态框
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }
        });
    </script>
@endsection
